#include <iostream>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;

class Solution {
public:
	bool isValid(string s) 
	{
		stack<char> stack;

		for (size_t i = 0; i < s.length(); ++i)
		{
			if (stack.size() > 0)
			{
				if (IsPair(stack.top(), s[i]))
				{
					stack.pop();
				}
				else
				{
					stack.push(s[i]);
				}
			}
			else
			{
				stack.push(s[i]);
			}
		}

		return stack.size() == 0;
	}
private:
	bool IsPair(char left, char right)
	{
		if (left == '{' && right == '}')
		{
			return true;
		}
		if (left == '[' && right == ']')
		{
			return true;
		}
		if (left == '(' && right == ')')
		{
			return true;
		}
		return false;
	}
};

int main()
{
	string a = "(]";
	Solution s;
	cout << (s.isValid(a)?"true":"false") << endl;

	return 0;
}